bitkeeper revision 1.1159.6.5 (41179cd0aGJI1_zvJCg05dqagSOrlw)
authormjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 9 Aug 2004 15:48:32 +0000 (15:48 +0000)
committermjw@wray-m-3.hpl.hp.com <mjw@wray-m-3.hpl.hp.com>
Mon, 9 Aug 2004 15:48:32 +0000 (15:48 +0000)
Fix problem with wrong domain name in vifctl down.
Add generic support to XendRoot to solve recursive
mutual import problem.

tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/XendRoot.py
tools/python/xen/xend/server/netif.py

index 2b8c9671f4ee06fac8eecaa36a9b36eb393ffef2..72fa81f56c6eca7ec979892e1809cff206c1dedf 100644 (file)
@@ -53,9 +53,8 @@ class XendDomain:
         # Hack alert. Python does not support mutual imports, but XendDomainInfo
         # needs access to the XendDomain instance to look up domains. Attempting
         # to import XendDomain from XendDomainInfo causes unbounded recursion.
-        # So we stuff the XendDomain instance (self) into XendDomainInfo's
-        # namespace as 'xd'.
-        XendDomainInfo.xd = self
+        # So we stuff the XendDomain instance (self) into xroot's components.
+        xroot.add_component("xen.xend.XendDomain", self)
         # Table of domain info indexed by domain id.
         self.db = XendDB.XendDB(self.dbpath)
         self.domain_db = self.db.fetchall("")
index fa5fd6b5741cd8cf2e35208dbbed05d0edda5943..dee5c1cdb220471d70ed39b6ddb93fafaa09ea40 100644 (file)
@@ -27,6 +27,7 @@ import sxp
 import XendConsole
 xendConsole = XendConsole.instance()
 from XendLogging import log
+from XendRoot import get_component
 
 import server.SrvDaemon
 xend = server.SrvDaemon.instance()
@@ -460,7 +461,8 @@ class XendDomainInfo:
             if c in '_-.': continue
             if c in string.ascii_letters: continue
             raise VmError('invalid vm name')
-        # See comment in XendDomain constructor about 'xd'.
+        # See comment in XendDomain constructor.
+        xd = get_component('xen.xend.XendDomain')
         if xd.domain_exists(name):
             raise VmError('vm name clash: ' + name)
         
index 3a6392803c488b47b3f5c6a5f560b398213439b6..9f23d1c68637410e1c06c6f0e3148eb50ed1d7ca 100644 (file)
@@ -50,6 +50,8 @@ class XendRoot:
 
     loglevel_default = 'DEBUG'
 
+    components = {}
+
     def __init__(self):
         self.rebooted = 0
         self.last_reboot = None
@@ -62,6 +64,24 @@ class XendRoot:
         #eserver.subscribe('xend.domain.created', self.event_handler)
         #eserver.subscribe('xend.domain.died', self.event_handler)
 
+    def add_component(self, name, val):
+        """Add a xend component.
+
+        @param name: component name
+        @param val:  component object
+        """
+        self.components[name] = val
+
+    def get_component(self, name):
+        """Get a xend component from its name.
+        This is used as a work-round for problems caused by mutually
+        recursive imports.
+
+        @param name: component name
+        @return: component object (or None)
+        """
+        return self.components.get(name)
+
     def start(self):
         eserver.inject('xend.start', self.rebooted)
 
@@ -202,3 +222,9 @@ def instance():
 
 def logger():
     return instance().get_logger()
+
+def add_component(name, val):
+    return instance().add_component(name, val)
+
+def get_component(name):
+    return instance().get_component(name)
index 41be86ac99da88055e37614fe84cb22a2c554e88..91601891209c16f4835e715a7efd8bf8416cab9a 100755 (executable)
@@ -10,6 +10,7 @@ from xen.xend import Vifctl
 from xen.xend.XendError import XendError
 from xen.xend.XendLogging import log
 from xen.xend import XendVnet
+from xen.xend.XendRoot import get_component
 
 import channel
 import controller
@@ -168,8 +169,14 @@ class NetDev(controller.Dev):
 
     def vifctl_params(self, vmname=None):
         dom = self.controller.dom
-        name = vmname or ('DOM%d' % dom)
-        return { 'domain': name,
+        if vmname is None:
+            xd = get_component('xen.xend.XendDomain')
+            try:
+                vm = xd.domain_lookup(dom)
+                vmname = vm.name
+            except:
+                vmname = 'DOM%d' % dom
+        return { 'domain': vmname,
                  'vif'   : self.get_vifname(), 
                  'mac'   : self.get_mac(),
                  'bridge': self.bridge,